package com.sxfech.project.a.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * Created by lihongliang on 2018/6/11.
 */
@Configuration
@EnableResourceServer
public class RemoteResourceConfiguration extends ResourceServerConfigurerAdapter {
    public RemoteResourceConfiguration() {
    }

    public void configure(HttpSecurity http) throws Exception {
        ((HttpSecurity)((ExpressionUrlAuthorizationConfigurer.AuthorizedUrl)((HttpSecurity)((HttpSecurity)((HttpSecurity)((ExpressionUrlAuthorizationConfigurer.AuthorizedUrl)((ExpressionUrlAuthorizationConfigurer.AuthorizedUrl)http.authorizeRequests().antMatchers(new String[]{"/**/*.js", "/**/*.ico", "/**/*.woff", "/**/*.json", "/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.gif", "/resources/**, /webjars/**", "/error"})).permitAll().anyRequest()).authenticated().and()).csrf().disable()).exceptionHandling().authenticationEntryPoint((request, response, authException) -> {
            response.sendError(401);
            String message = "{\"code\":\"401\",\"message\":\"no login\"}";
            response.getOutputStream().write(message.getBytes());
        }).and()).authorizeRequests().anyRequest()).authenticated().and()).httpBasic();
    }
}

